﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HippoScript
{
    /// <summary>
    /// JSEngine脚本引擎
    /// </summary>
    public class JSEngine : Engine
    {
        /// <summary>
        /// 新建一个引擎
        /// </summary>
        public JSEngine()
            : base(new JSAnalyze(), new JSEvaluatorFactory())
        {

        }
        /// <summary>
        /// 取得一个copy对象
        /// 新对象拥有同样的状态值，但是context和程序集都是新的。
        /// </summary>
        /// <returns></returns>
        public override Engine Copy()
        {
            JSEngine engineNew = new JSEngine();
            engineNew.Analyze = new JSAnalyze();
            engineNew.Context = ObjectExtension.DeepClone(this.Context) as ScriptContext;
            engineNew.EvaluatorFactory = new JSEvaluatorFactory();
            engineNew.EvaluatorFactory.Evaluator = engineNew.EvaluatorFactory.Create(engineNew.Context);
            engineNew.EvaluatorFactory.Evaluator.RefreshStateByContext();
            engineNew.EvaluatorFactory.Evaluator._evaluatorObj = ObjectExtension.DeepClone(this.EvaluatorFactory.Evaluator._evaluatorObj);
            return engineNew;
        }
    }
}
